package com.example.feign.controller;

import com.example.feign.entity.Course;
import com.example.feign.feign.CourseFeign;
import com.example.feign.util.EntityToMap;
import com.example.feign.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/course")
public class CourseFeignController {
    @Autowired
    CourseFeign courseFeign;

    @GetMapping("/get")
    public Response getCourse(@RequestParam(value = "page",required = false) Integer page,
                              @RequestParam(value = "size",required = false) Integer size,
                              @RequestParam(value = "spId",required = true) String spId,
                              Course course){
        Map map = new HashMap<>();
        map = EntityToMap.object2Map(course);
        return courseFeign.getCourse(page, size, spId, map);
    }

    @GetMapping("/getAll")
    public Response getAllCourse(){
        return courseFeign.getAllCourse();
    }

    @PostMapping("/add")
    public Response addCourse(Course course){
        return courseFeign.addCourse(course);
    }

    @PutMapping("/update")
    public Response updateCourse(Course course){
        return courseFeign.updateCourse(course);
    }

    @PutMapping("/del")
    public Response delCourse(@RequestParam(value = "courseId",required = true) String courseId){
        return courseFeign.delCourse(courseId);
    }
}
